# Maintainer: George Rawlinson <grawlinson@archlinux.org>

pkgname=nomad-driver-containerd
_pkgname=containerd-driver
pkgver=0.9.4
pkgrel=1
pkgdesc='A nomad taskdriver for containerd containers'
arch=('loong64' 'x86_64')
url='https://github.com/Roblox/nomad-driver-containerd'
license=('MPL2')
depends=('nomad' 'containerd')
makedepends=('git' 'go')
options=('!lto')
_commit=4f174572bcf2e193a5144714b2e56bb3a79720a1	#refs/tags/v0.9.4
source=("$pkgname::git+$url.git#commit=$_commit")
b2sums=('SKIP')

pkgver() {
  cd "$pkgname"

  git describe --tags | sed 's/^v//'
}

prepare() {
  cd "$pkgname"

  # create directory for build output
  mkdir build

  # download dependencies
  go mod download
}

build() {
  cd "$pkgname"

  go build -v \
    -trimpath \
    -buildmode=pie \
    -mod=readonly \
    -modcacherw \
    -ldflags "-linkmode external -extldflags \"${LDFLAGS}\"" \
    -o build \
    .
}

package() {
  cd "$pkgname"
  install -vDm755 "build/$pkgname" "$pkgdir/usr/lib/nomad/plugins/$_pkgname"
}
